from typing import Optional, Dict
from collections import defaultdict
from SimTrader.event_engine import EventEngine
from SimTrader.objects import Order, Trade, AccountInfo
from SimTrader.constants import OrderStatus, TradeStatus


class AccountEngine(object):
    """账户引擎"""
    def __init__(self, event_engine: EventEngine, account_info: Optional[Dict, AccountInfo]):
        """
        实现一个账户引擎实例
        :param event_engine: 事件引擎
        :param acount_info: 账户信息
        """
        self.__event_engine = event_engine
        self.__account_info = account_info if isinstance(account_info, AccountInfo) else AccountInfo(**account_info)
        # 保存账户与策略的对应关系
        self.__account_strategy = defaultdict(list)

    def __process_order_func(self):
        """order处理函数"""
        pass

    def __process_trade_func(self):
        """trade处理函数"""
        pass

    def __process_tick_func(self):
        """
        tick行情处理函数
        """
        pass

    def __process_bar_func(self):
        """
        bar行情处理函数
        """
        pass

    def __register_strategy(self, account_id, strategy):
        """
        保存账户与策略的对应关系
        """
        # 对应关系中已经保存account_id和strategy
        if account_id in self.__account_strategy and strategy in self.__account_strategy[account_id]:
            return
        self.__account_strategy[account_id].append(strategy)